import 'dart:convert';

class FollowItem {
  String? uid;
  String? username;
  String? avatar;
  bool? isfollow;
  String? userId;
  int? fanCount;
  int? time; // Assuming time is a Unix timestamp in milliseconds

  FollowItem({
    required this.uid,
    required this.username,
    required this.avatar,
    required this.isfollow,
    required this.userId,
    required this.fanCount,
    required this.time,
  });

  // 从JSON映射创建FollowItem实例
  factory FollowItem.fromJson(Map<String, dynamic> json) {
    return FollowItem(
      uid: json['uid'],
      username: json['username'],
      avatar: json['avatar'],
      isfollow: json['isfollow'],
      userId: json['userId'],
      fanCount: int.parse(json['fanCount']),
      time: json['time'],
    );
  }

  // 将FollowItem实例转换为JSON映射
  Map<String, dynamic> toJson() {
    return {
      'uid': uid,
      'username': username,
      'avatar': avatar,
      'isfollow': isfollow,
      'userId': userId,
      'fanCount': fanCount.toString(),
      'time': time,
    };
  }
}

class FollowItemList {
  List<FollowItem> items;

  FollowItemList({required this.items});

  // 从JSON数组字符串创建FollowItemList实例
  factory FollowItemList.fromJson(List<dynamic> list) {
    return FollowItemList(
      items: list.map((json) => FollowItem.fromJson(json)).toList(),
    );
  }

  // 将FollowItemList实例转换为JSON数组字符串
  String toJson() {
    return json.encode(items.map((item) => item.toJson()).toList());
  }
}
